<?php
/*
Plugin Name: galerie Nicolas Gbenou
Description: galerie permet la création d'une galerie de photos soumises par un formulaire
Version: 1.0.0
*/

    class wp_galerie
    {
        /**
         * Constructor
         */
		var $adminOptionsName = 'wp_galerieAdminOptions';  
		
        function wp_galerie()
        {
            
        }
		function getAdminOptions() 
		{
			$wp_galerieAdminOptions = array(
					'enabled' => 'true',
					'exclude_ips' => ''
				);
			$wp_galerieOptions = get_option($this->adminOptionsName);
			if (!empty($wp_galerieOptions))
			{
				foreach ($wp_galerieOptions as $key => $option)
					$wp_galerieAdminOptions[$key] = $option;
			}
			update_option($this->adminOptionsName, $wp_galerieAdminOptions);
			return $wp_galerieAdminOptions;
		}
		function init() 
		{
			$this->getAdminOptions();
		}
		function printAdminPage() {
			$options = $this->getAdminOptions();
			if (isset($_POST['update_wp_jschatSettings'])) {
				if (isset($_POST['enabled'])) {
					$options['enabled'] = $_POST['enabled'];
				}
				if (isset($_POST['exclude_ips'])) {
					$options['exclude_ips'] = $_POST['exclude_ips'];
				}
				update_option($this->adminOptionsName, $options);
				print '<div class="updated"><p><strong>';
				_e("Paramètres mis à jour", "wpjschat");
				print '</strong></p></div>';
			   
			}
			include('admin_settings.php'); // include du formulaire HTML
		}

        function hello_world($content){ 
            $text = "<p>Hello Word</p>"; 
            return $text.$content; 
         
        }
        function display_form($content){
		    global $wpdb;
			include('form.php');
            $text = '';
           /* $text = '
            <div id="respond">
                <form method="post" action="'.$_SERVER["REQUEST_URI"].'">
                <p>Hello form</p>
                <p><label>Nom</label><input id="name"><span class="required"">*</span></p>
                <p><label>Prénom</label><input id="name"><span class="required"">*</span></p>
                <p><label>Email</label><input id="name"><span class="required"">*</span></p>
                <p><label>Photo</label><input id="name" type="file""><span class="required"">*</span></p>
                <p><input name="submit" value="envoyer" type="submit"></p>
                </form>
            </div>
            '; */
            if(isset($_POST['submit'])){
            echo'recu';
			include('image_valide2.php');
            }
            return $text.$content; 
        }
        
		function display_galerie(){
		  global $wpdb;
		  wp_enqueue_script('masonry', '/wp-content/plugins/galerie/jquery.masonry.min.js');
		  wp_enqueue_script('fancybox', '/wp-content/plugins/galerie/fancybox/jquery.fancybox-1.3.1.js');
		  wp_enqueue_style('wp_jschat', '/wp-content/plugins/galerie/fancybox/jquery.fancybox-1.3.1.css');
		  include('template_galerie.php');
		
		}
        
    }
    if (class_exists('wp_galerie')) {
       $galerie = new wp_galerie();
       add_shortcode( 'form-galerie', array($galerie, 'display_form'), 1);
	   add_shortcode( 'galerie', array($galerie, 'display_galerie'), 1);
	   
    }

	
	function galerie_AdminMenu() {
	  if (function_exists('add_options_page')) {
	  $plugin_page_options = add_options_page('Nom du Lien', 'Galerie', 'administrator', basename(__FILE__), 'fonction_de_la_page_options');
	  }
	}
	function fonction_de_la_page_options() {
      global $wpdb;
	  if (!current_user_can('administrator'))  {
		wp_die( __('You do not have sufficient permissions to access this page.') );
		echo 'die';
	  }

	  echo '<div class="wrap">';
	  echo '<p>Ceci est l\'endroit où placer le formulaire des options.</p>';
	  echo '</div>';
	  include('admin/admin.php');

	}
	add_action( 'admin_menu', 'galerie_AdminMenu' );
?>
